﻿using Libs;
using WriteForFighting.Game.Asset;
using WriteForFighting.Game.View;

namespace WriteForFighting.Game
{
    sealed class GameMain
    {
        private static int gameTickCount;

        private FPSControler fpsControler = new FPSControler(GD.FPS);
        private ViewBase activeView;

        public GameMain()
        {
            activeView = new ViewGameMain();
        }

        public static void Init()
        {
            Drawable.Init();
            Font.Init();
            Sound.Init();
        }

        public void Start()
        {
            DX.SetDrawScreen(DX.DX_SCREEN_BACK);
            while ((DX.ProcessMessage() != -1) &&
                    fpsControler.WaitNextFrame())
            {
                gameTickCount++;

                //アップデート
                activeView.Update(gameTickCount);

                if (fpsControler.IsDraw())
                {
                    DX.ClearDrawScreen();

                    //描画
                    activeView.Draw(gameTickCount);

                    DX.ScreenFlip();

                    fpsControler.CalcFps();
                    if (gameTickCount % 60 == 0)
                    {
                        DX.SetWindowText(GD.APP_NAME + " : " + GD.VERSION + "   fps : " + fpsControler.GetFpsReal());
                    }
                }
            }
        }
    }
}
